﻿<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of user
 *
 * @author grigoriev
 */
class user extends model {
    //public $id;
    //public $fields = array();
    public $extrafields = array();


    public function __construct($id=null){
        parent::__construct($id, "user");
        //parent::associate('groups');
    }

    public function login($login, $pass){
        $query = "select id from users where login=\"$login\" and pass=md5(\"$pass\")";
        $res = mysql_query($query);
        if(@mysql_num_rows($res) == 1){
            $r = mysql_fetch_row($res);
            $_SESSION['user_id'] = $r[0];
            return true;
        }else{
            $_SESSION['errmsg']['login'] = 'ПЫЩЩ! Логин/пароль не опознаны';
            return false;
        }
    }

    public function logout(){
        unset($_SESSION['user_id']);
    }

    public function getextrainfo(){
        $extraquery = "select * from userextras where propowner=$this->id";
        $extrares = mysql_query($extraquery);
        if(mysql_num_rows($extrares)){
            while($extrar = mysql_fetch_row($extrares)){
                $this->extrafields[$extrar[2]][$extrar[1]] = $extrar[3];
            }
        }
    }

    private function add_assoc($a){
        array_push($this->asscociated, $a);
    }
}
?>